<template>
<!-- 退保计算结果页 -->
    <el-card class="box-card">
        <div slot="header" class="clearfix">
            <span style="line-height: 36px;">计算结果</span>
             <el-button type="primary" style="float:right;margin-left:20px"  @click="recompute">
                    重新计算
                </el-button>
                
            <el-button type="primary" style="float:right" @click="submit">
                提交
            </el-button>
        </div>
        <el-form :inline="true" class="demo-form-inline">
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="投保单号:" label-width="180px">
                        <el-input v-model="model.SALESDETAIL_ID" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="退保时间:" label-width="180px" :disabled="true">
                        <el-date-picker type="date" placeholder="选择日期" v-model="model.BACKSALE_TIME"></el-date-picker>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="是否全款:" label-width="180px" :disabled="true">
                            <el-radio-group v-model="model.BACKSALE_TYPE" :disabled="true"> 
                            <el-radio class="radio"  label="全款">全款</el-radio>
                            <el-radio class="radio"  label="非全款">非全款</el-radio>
                             </el-radio-group>
                        </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="退款金额: " label-width="180px">
                        <el-input v-model="model.BACKSALE_MONEY" class="inline-input" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6" v-if="model.BACKSALE_TYPE=='非全款'">
                    <div style="line-height:40px;" v-if="model.BACKSALE_SEALMONEY==model.BACKSALE_MONEY*0.75">
                          (0.75)
                    </div>
                   <div style="line-height:40px;" >
                         (0.65)
                    </div>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="上传退款凭证: " label-width="180px">
                      <el-button type="primary" class="fileselect"  v-if="type!='退保审核'">
                                    <input type="file" @change="upload('BACKSALE_CERTIFICATEDOC',$event,1)" value="" id="fileup1"> 上传附件
                                </el-button>
                                 <el-button type='primary' @click="dowload('BACKSALE_CERTIFICATEDOC')" v-else>
                                        下载
                                    </el-button>   
                            </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="非全退上传发票: " label-width="180px">
                       <el-button type="primary" class="fileselect" v-if="type!='退保审核'">
                                    <input type="file" @change="upload('BACKSALE_INVOICEDOC',$event,2)" value="" id="fileup2"> 上传附件
                                </el-button>
                                 <el-button type='primary' @click="dowload('BACKSALE_INVOICEDOC')" v-else>
                                        下载
                                    </el-button>   
                            </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="20">
                <el-col :span="20">
                    <el-form-item label="退款详情说明: " label-width="180px">
                        <el-input type="textarea" v-model="model.BACKSALE_CONTENT" style="width:300px;" :disabled="true"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        </div>
    </el-card>
</template>

<script>
import api from "@/js/api";
export default {
  data() {
    return {
      model: {
        BACKSALE_ID: "",
        BACKSALE_SALENUMBER: "",
        BACKSALE_TIME: "",
        BACKSALE_TYPE: "",
        BACKSALE_MONEY: "",
        BACKSALE_POLICYDOC: "",
        BACKSALE_APPLICATIONDOC: "",
        BACKSALE_INVOICEOLDDOC: "",
        BACKSALE_CARDDOC: "",
        BACKSALE_CERTIFICATEDOC: "",
        BACKSALE_INVOICEDOC: "",
        BACKSALE_CONTENT: "",
        SALESDETAIL_ID: "",
        BACKSALE_CHECKSTATE: "",
        BACKSALE_CHECKMESSAGE: ""
      }
    };
  },
  props: {
    type: {
      type: String,
      default: "申请"
    },
    content: {
      type: Object,
      default: { SALESDETAIL_ID: "", BACKSALE_SALENUMBER: "" }
    }
  },
  methods: {
    submit() {
      this.model.BACKSALE_CHECKSTATE = "退保完成";
      let that=this;
      api.BACKSALEUpdate(this, this.model,function(msg){    
           that.$notify.success({
                title: '成功',
                message: '确认成功'
            });
            that.$emit('close');      
      });
    },
    //重新计算
    recompute() {
      let that = this;
      api.BACKSALEUpdate(this, this.model, function(msg) {
        that.$notify.success({
          title: "成功",
          message: "修改成功"
        });
        that.getBackDate();
      });
    },
    //文件上传
    upload(name, event, id) {
      let file = event.target.files[0];
      if (file) {
        const formData = new FormData();
        formData.append("file", file);
        let that = this;
        api.uploadFile(this, formData, function(msg) {
          eval(document.getElementById("fileup" + id)).value = "";
          that.model[name] = msg.Result.FilesList[0];
        //   console.log(that.model);
        });
      }
    },
    //获取退报数据
    getBackDate() {
      let that = this;
      api.BACKSALEGetOne(that, { Id: this.content.SALESDETAIL_ID }, function(
        msg
      ) {
        that.model = msg.Result;
        that.model.BACKSALE_TIME = that.model.BACKSALE_TIME + "Z"; //告诉他 这是标准标准时间
      });
    },
    dowload(name) {
      var url = this.model[name];
      window.open(api.download(url));
      //   console.log(url);
    }
  },
  created() {
    // console.log(this.content);
    this.model.SALESDETAIL_ID = this.content.SALESDETAIL_ID;
    this.model.BACKSALE_SALENUMBER = this.content.SALESDETAIL_INSURANCENUMBER;
    this.getBackDate();
  }
};
</script>

<style>
.inline-input {
  display: inline !important;
}
</style>
